package com.bit.net;

/**
 * 消息（package data）常量类
 * <p>
 * 数据包格式定义如下：
 * <p>
 * +--------------+     +----------------+     +----------------+     +--------------+     +----------+     +------+
 * | magic number | --> | version number | --> | package length | --> | package type | --> | reserve  | --> | body |
 * +--------------+     +----------------+     +----------------+     +--------------+     +----------+     +------+
 * <p>
 * </p>
 *
 * @since 2018/10/10
 */
public abstract class Messages {

    /**
     * 魔数
     */
    public static final byte[] MAGIC_NUMBER;
    /**
     * 魔数长度
     */
    public static final int MAGIC_NUMBER_SIZE = 2;
    /**
     * 报文头长度
     */
    public static final int PKG_HEAD_SIZE = 8;
    /**
     * 最小包长度
     */
    public static final int MIN_PKG_SIZE = PKG_HEAD_SIZE;
    /**
     * 报文默认版本号
     */
    public static final short DEFAULT_VERSION = 0x00;
    /**
     * 报文版本号下标
     */
    public static final int VERSION_INDEX = 2;
    /**
     * 报文长度下标
     */
    public static final int PKG_SIZE_INDEX = 3;
    /**
     * 指令下标
     */
    public static final int CMD_INDEX = 5;
    /**
     * 报文体下标
     */
    public static final int BODY_INDEX = 8;
    /**
     * 保留位长度
     */
    public static final int RESERVED_SIZE = 2;
    /**
     * 保留位
     */
    public static final byte[] RESERVED;

    static {
        MAGIC_NUMBER = new byte[MAGIC_NUMBER_SIZE];
        MAGIC_NUMBER[0] = (byte) 0xcc;
        MAGIC_NUMBER[1] = (byte) 0xcc;

        RESERVED = new byte[RESERVED_SIZE];
        RESERVED[0] = (byte) 0x00;
        RESERVED[1] = (byte) 0x00;
    }
}


